package meatslope2.gameengine.input;

import javax.microedition.khronos.opengles.GL10;

import meatslope2.gameengine.gameobjects.model.DrawableGameObject;
import meatslope2.gameengine.gameobjects.model.Sprite;
import meatslope2.gameengine.primatives.Vector2;

public abstract class CircleButton extends DrawableGameObject implements IButton
{
	// ===========================================================
	// Members
	// ===========================================================
	
	protected final int radius;
	private final int radiusSquared;
	
	// ===========================================================
	// Getters/Setters
	// ===========================================================
	
	protected final float getCenterX()
	{
		return this.position.x + radius;
	}
	
	protected final float getCenterY()
	{
		return this.position.y + radius;
	}
	
	// ===========================================================
	// Constructors
	// ===========================================================
	
	public CircleButton(Sprite sprite, int diameter, int posX, int posY)
	{
		super(sprite, diameter, diameter, false);
		
		this.position.x = posX;
		this.position.y = posY;
		
		this.radius = diameter / 2;
		this.radiusSquared = radius * radius;
	}
	
	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================
	
	public void performAction() 
	{
		//By default, do nothing
	}
	
	public boolean pressed(Vector2 touchPosition) 
	{
		final float x = touchPosition.x;
		final float y = touchPosition.y;
		
		final float diffX = getCenterX() - x;
		final float diffY = getCenterY() - y;
		
		return this.radiusSquared > diffX * diffX + diffY * diffY;
	}

	@Override
	public void draw(GL10 pGL) 
	{
		this.sprite.draw(pGL, this);
	}
}
